﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _6_4
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if(TextBox1.Text.Trim().Equals("mr")&&TextBox2.Text.Trim().Equals("mrsoft"))
            {
                Session["username"] = TextBox1.Text.Trim();
                if (CheckBox1.Checked)
                {
                    if (Request.Cookies["username"] == null)
                    {
                        Response.Cookies["username"].Expires = DateTime.Now.AddDays(30);
                        Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(30);
                        Response.Cookies["username"].Value = TextBox1.Text.Trim();
                        Response.Cookies["userpwd"].Value = TextBox2.Text.Trim();
                    }
                }
                Response.Redirect("admin.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "alert('用户名或密码错误！');", true);
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (Request.Cookies["username"] != null)
            {
                if (Request.Cookies["username"].Value.Equals(TextBox1.Text.Trim()))
                {
                    TextBox2.Attributes["value"] = Request.Cookies["userpwd"].Value;
                }
            }
        }
    }

}